<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>{$basic.title}</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link href="__LAYUI__/css/layui.css" rel="stylesheet">
    <link href="__LAYUI__/css/ah.css" rel="stylesheet">
</head>
<body>
<div class="wrapper-content">
<div class="ibox">
	<div class="ibox-title"><h3>增加节点</h3>
	</div>
	<div class="ibox-content">
		<form class="layui-form" enctype="multipart/form-data" id="amData" action="{:url('node/add')}">
				  <div class="layui-form-item">
					<label class="layui-form-label">节点名称</label>
					<div class="layui-input-block">
					  <input type="text" name="node_name" autocomplete="off" placeholder="请输入名称" class="layui-input">
					</div>
				  </div>
				  <div class="layui-form-item">
					<label class="layui-form-label">根节点</label>
					<div class="layui-input-block">
					  <input type="text" name="module_name" value="admin" autocomplete="off" placeholder="请输入根节点,如:admin" class="layui-input">
					</div>
				  </div>
					<div class="layui-form-item">
					  <label class="layui-form-label">控制器</label>
					  <div class="layui-input-inline">
						<input type="text" name="control_name"  autocomplete="off" placeholder="请输入控器器,如:article" class="layui-input">
					  </div>
					</div>
					<div class="layui-form-item">
					  <label class="layui-form-label">操作</label>
					  <div class="layui-input-inline">
						<input type="text" name="action_name" autocomplete="off" placeholder="请输入操作,如:add" class="layui-input">
					  </div>
					</div>
				  <div class="layui-form-item">
					<label class="layui-form-label">是否菜单</label>
					<div class="layui-input-inline">
					  <input type="checkbox" name="is_menu"  lay-skin="switch" lay-filter="switch" lay-text="ON|OFF">
					</div>
				  </div>
					<div class="layui-form-item">
					  <label class="layui-form-label">上级节点</label>
					  <div class="layui-input-inline" id="LAY-auth-tree-convert-select-dom">
						
					  </div>
					</div>
					<div class="layui-form-item">
							<label class="layui-form-label">图标</label>
							<div class="layui-input-inline">
							  <input type="text" id="icoValue" name="icon"  class="layui-input">
							</div>
					</div>
							<button type="button" class="layui-btn" lay-submit lay-filter="saveData">保存提交</button>
		</form>
	</div>
</div>
</div>
</body>
<script src="__LAYUI__/layui.js"></script>

<!-- 树转单选树的DOM -->
<script type="text/html" id="LAY-auth-tree-convert-select">
        <select name="parentId" class="layui-input" lay-filter="{{d.layFilter}}">
			<option value="0">顶级节点</option>
          {{# layui.each(d.list, function(index, item) { }}
          <option value="{{item.value}}">{{item.name}}</option>
          {{# });}}
        </select>
</script>
<!--隐藏左侧操作的DOM-->
<script>
function getValue(v) {
		document.getElementById("icoValue").value=v; 
	}
layui.config({
	base: '__LAYUI__/exts/',
}).extend({
	authtree: 'authtree',
});
  layui.use(['layer', 'authtree', 'jquery', 'form', 'code', 'laytpl'], function(){
    var $ = layui.jquery;
    var layer = layui.layer;
    var authtree = layui.authtree;
    var form = layui.form;
    var laytpl = layui.laytpl;
	var xaoam ={
		  close:function(msg){
			  layer.msg(msg);
			  if(parent.length > 0){
				  let index = parent.layer.getFrameIndex(window.name);
				  parent.layer.close(index);
				  parent.Wxaoam.init();
			  }
			  
		  },
		  tool:function(){
				$('#icoValue').click(function(){
					layer.open({
					  type: 2,
					  title: ' ',
					  area: ['380px', '260px'],
					  content: ['__UI__/ico.html', 'no'],
		  
					});
				});
				form.on('submit(saveData)', function(data){
					var action = $(this).parent('form').attr('action');
					var index = parent.layer.getFrameIndex(window.name);
					var Fdata = new FormData(document.getElementById("amData"));
						if(Fdata.get('is_menu') == 'on'){
							Fdata.append('is_menu', 1);
						}else{
							Fdata.append('is_menu', 0);
						}
					$.ajax({
						url:action,
						data:Fdata,
						dataType:'json',
						type:'POST',
						contentType: false,
						processData: false,
						success:function(res){
							if(res.code == 200){
								xaoam.close(res.msg);
							}else{
								layer.msg(res.msg);
							}
						}
					})
				  return false; 
				});
		  },
		init:function(){
			$.ajax({
				      url: "{:url('node/lists')}",
				      dataType: 'json',
				      success: function(data){
				  	  var trees = authtree.listConvert(data.data, {
				  	      primaryKey: 'id'
				  	      ,startPid: 0
				  	      ,parentKey: 'parentId'
				  	      ,nameKey: 'node_name'
				  	      ,valueKey: 'id'
				  	  });
			    var selectList = authtree.treeConvertSelect(trees, {
			      childKey: 'list',
			    });
			    var string =  laytpl($('#LAY-auth-tree-convert-select').html()).render({
			      layFilter: 'LAY-auth-tree-convert-select-input',
			      list: selectList,
			      code: JSON.stringify(data, null, 2),
			    });
			    $('#LAY-auth-tree-convert-select-dom').html(string);
			    form.render('select');
			  }
			});
		}
	};
	xaoam.tool();
	xaoam.init();
  });
</script>
</html>
